package com.zangs.emqx_expand.web.controller.emqx;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zangs.emqx_expand.common.annotation.Log;
import com.zangs.emqx_expand.common.core.controller.BaseController;
import com.zangs.emqx_expand.common.core.domain.AjaxResult;
import com.zangs.emqx_expand.common.enums.BusinessType;
import com.zangs.emqx_expand.emqx.domain.MqttAcl;
import com.zangs.emqx_expand.emqx.service.IMqttAclService;
import com.zangs.emqx_expand.common.utils.poi.ExcelUtil;
import com.zangs.emqx_expand.common.core.page.TableDataInfo;

/**
 * MQTT 权限Controller
 * 
 * @author zangs
 * @since 2025-01-26
 */
@RestController
@RequestMapping("/emqx/acl")
public class MqttAclController extends BaseController
{
    @Autowired
    private IMqttAclService mqttAclService;

    /**
     * 查询MQTT 权限列表
     */
    @PreAuthorize("@ss.hasPermi('emqx:acl:list')")
    @GetMapping("/list")
    public TableDataInfo list(MqttAcl mqttAcl)
    {
        startPage();
        List<MqttAcl> list = mqttAclService.selectMqttAclList(mqttAcl);
        return getDataTable(list);
    }

    /**
     * 导出MQTT 权限列表
     */
    @PreAuthorize("@ss.hasPermi('emqx:acl:export')")
    @Log(title = "MQTT 权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MqttAcl mqttAcl)
    {
        List<MqttAcl> list = mqttAclService.selectMqttAclList(mqttAcl);
        ExcelUtil<MqttAcl> util = new ExcelUtil<MqttAcl>(MqttAcl.class);
        util.exportExcel(response, list, "MQTT 权限数据");
    }

    /**
     * 获取MQTT 权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('emqx:acl:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mqttAclService.selectMqttAclById(id));
    }

    /**
     * 新增MQTT 权限
     */
    @PreAuthorize("@ss.hasPermi('emqx:acl:add')")
    @Log(title = "MQTT 权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MqttAcl mqttAcl)
    {
        return toAjax(mqttAclService.insertMqttAcl(mqttAcl));
    }

    /**
     * 修改MQTT 权限
     */
    @PreAuthorize("@ss.hasPermi('emqx:acl:edit')")
    @Log(title = "MQTT 权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MqttAcl mqttAcl)
    {
        return toAjax(mqttAclService.updateMqttAcl(mqttAcl));
    }

    /**
     * 删除MQTT 权限
     */
    @PreAuthorize("@ss.hasPermi('emqx:acl:remove')")
    @Log(title = "MQTT 权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mqttAclService.deleteMqttAclByIds(ids));
    }
}
